/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pos.Driving.Path;

/**
 *
 * @author Administrator
 */

import javax.media.j3d.*;
import javax.vecmath.*;
import pos.Driving.Train.Train;
import pos.utils.ObjectFactory;

/**
 *
 * @author Administrator
 */
public class ATOStationSignture extends TransformGroup implements Attachable {

    private double D;
    private int stationID;
    private boolean isRightDoorOpen;
    private PosPoint P;
    private static Group model;
    

    public ATOStationSignture(int stationID, boolean isRightOpen) {
        if (model==null) model=ObjectFactory.createObject("Model.Rail.ATP.Speed");
        this.stationID = stationID;
        this.isRightDoorOpen = isRightOpen;
    }
    

    @Override
    public boolean test(double d) {
        if (Math.abs(d-this.D)<5)
            return true;
        else 
            return false;
    }

    @Override
    public Object action(Train train) {
        if (isRightDoorOpen)
            train.setOnStation(stationID, Train.ALLOW_RIGHT_DOOR_OPEN);
        else
            train.setOnStation(stationID, Train.ALLOW_LEFT_DOOR_OPEN);
        return null;
    }

    @Override
    public Object getInfo() {
        return new Double[]{this.D,(double)stationID};
    }


    @Override
    public void setLocation(double d,PosPoint p) {
        
        this.D = d;
        this.P = p;
        Transform3D transH = new Transform3D(),
                transV = new Transform3D(),
                transT = new Transform3D();
        transV.rotY(P.AngV);
        transH.rotX(P.AngH);
        transT.set(new Vector3d(P.pos.x, P.pos.y, P.pos.z));
        transT.mul(transV);
        transT.mul(transH);
        this.setTransform(transT);
        this.addChild(model.cloneTree());
    }

    @Override
    public Object setParam(Object param) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
